package com.acwing.partition13;

import java.io.*;
import java.util.Arrays;

/**
 * @author `RKC`
 * @date 2022/3/2 10:25
 */
public class AC1207大臣的旅费_树形dp {

    private static final int N = 100010;
    private static int[] h = new int[N], e = new int[N << 1], ne = new int[N << 1], w = new int[N << 1];
    //dist[i]表示从节点i出发走向以i为根的子树能够到达的最远节点的距离
    private static int[] dist = new int[N];
    private static boolean[] st = new boolean[N];
    private static int n, idx = 0, answer = 0;

    private static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    private static final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        n = Integer.parseInt(reader.readLine().split(" ")[0]);
        Arrays.fill(h, -1);
        for (int i = 0; i < n - 1; i++) {
            String[] ss = reader.readLine().split("\\s+");
            int a = Integer.parseInt(ss[0]), b = Integer.parseInt(ss[1]), c = Integer.parseInt(ss[2]);
            add(a, b, c);
            add(b, a, c);
        }
        dfs(1);
        long ans = answer * 11L + (long) answer * (answer - 1) / 2;
        writer.write(ans + "\n");
        writer.flush();
    }

    private static void dfs(int u) {
        st[u] = true;
        for (int i = h[u]; i != -1; i = ne[i]) {
            int v = e[i];
            if (st[v]) continue;
            dfs(v);
            answer = Math.max(answer, dist[u] + dist[v] + w[i]);
            dist[u] = Math.max(dist[u], dist[v] + w[i]);
        }
    }

    private static void add(int a, int b, int c) {
        e[idx] = b;
        ne[idx] = h[a];
        h[a] = idx;
        w[idx++] = c;
    }
}
